package com.imti.service.impl;


import com.imti.mapper.ClazzMapper;
import com.imti.model.Clazz;
import com.imti.model.dto.ClazzUser;
import com.imti.service.ClazzService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {

    @Resource
    ClazzMapper clazzMapper;

    // 注入RedisTemplate
    private final RedisTemplate<String, Object> redisTemplate;

    public ClazzServiceImpl(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public List<Clazz> findAllClazz(Clazz clazz) {
        return clazzMapper.findAllClazz(clazz);
    }

    @Override
    public int addClazzById(Clazz clazz) {
        Integer userId = (Integer) redisTemplate.opsForValue().get("userId");
        clazz.setUserId(userId);
        return clazzMapper.addClazzById(clazz);
    }

    @Override
    public int deleteClazz(Integer id) {
        return clazzMapper.deleteClazz(id);
    }

    @Override
    public List<ClazzUser> select(ClazzUser clazz) {
        return clazzMapper.select(clazz);
    }

    @Override
    public List<ClazzUser> selectClazz(Integer id) {
        return clazzMapper.selectClazz(id);
    }
}
